import createPersistedState from 'vuex-persistedstate';
import * as Cookies from "js-cookie";

/**
 * cookie持久化储存
 */
let cookieStorage = {
    getItem: key => {
        let data = Cookies.get(key);

        if (!data) {
            return false;
        }

        data = JSON.parse(data)

        return data;
    },

    setItem: function (key, value) {
        return Cookies.set(key, value, { expires: 7, secure: false, path: '/' });
    },
    removeItem: key => Cookies.remove(key)
};

export default ({ store }) => {

    createPersistedState({
        paths: ['token', 'userInfo'],
        storage: cookieStorage,
    })(store);
};
